function MinePublishObjController(analyseId){
	
	this.analyseId = analyseId;
	/**
	 * 初始化全部流程列表
	 */
	this.initAllFlowGrid = function(data){
		if(!this.flowGrid){
			this.flowGrid = $('#mine-publish-all-grid').jqGrid({
				datatype : "local",
				data : data,
				height : $('#mine-publish-all-grid').parent().height() - 85,
				width : $('#mine-publish-all-grid').parent().width()-5,
				rownumbers : true,
				hidegrid : false,
				shrinkToFit : true,
				resizable:false,
				loadui:'disable',
				colNames : [ 'id', 
				             'appId',
				             'parentId',
				             TempoUtils.locale("mine.publish-all-flow-grid-column-name"),
				             TempoUtils.locale("mine.publish-all-flow-grid-column-author"),
				             TempoUtils.locale("mine.publish-all-flow-grid-column-createtime"),
				             TempoUtils.locale("mine.publish-grid-column-opt")],
				colModel : [{
							name : 'id',
							index : 'id',
							hidden : true
						},{
							name : 'appId',
							index : 'appId',
							hidden : true,
						},{
							name : 'parentId',
							index : 'parentId',
							hidden : true
						},{
							name : 'name',
							index : 'name',
							resizable:false,
							sortable : false,
							formatter : function(obj, grid, rows, state) {
								return obj;
							}
						},{
							name : 'author',
							index : 'author',
							width : 80,
							sortable:false
						},{
							name : 'createTime',
							index : 'createTime',
							resizable:false,
							sortable : false,
							formatter : function(obj, grid, rows, state) {
								if(obj && $.isNumeric(obj)){
									return DateUtils.formatDateTime(new Date(obj), 'yyyy-MM-dd HH:mm:ss');
								}
								return '';
							}
						},{
							name : '',
							index : '',
							sortable : false,
							width : 100,
							align : 'left',
							fixed : false,
							formatter : function(obj, grid, rows, state) {
								var edit = $("<a>").attr("href", "javascript:;void(0)").append($("<span>").attr("rowid", rows.id).addClass("ui-icon ui-icon-tag")).attr("title",  TempoUtils.locale("mine.publish-all-flow-grid-optpublish")).addClass('ui-corner-all gridoptbtn publishBtn');
								return edit.prop("outerHTML");
							}
						}],
				gridComplete : function(rowid,row) {
					bindAllFlowGridEvent();
				},
				loadComplete : function(datas){
					$('#mine-publish-all-grid').find('tr:odd').addClass('trodd');
					$('#mine-publish-all-grid').find('tr:even').addClass('treven');
				},
				viewrecords : true,
				hoverrows : false
			});
		}else{
			this.flowGrid.jqGrid('clearGridData');
			if(data && data.length > 0){
				for (var i = 0; i < data.length; i++) {
					this.flowGrid.jqGrid('addRowData', data[i].id, data[i], i)
				}
			}
			$('#mine-publish-all-grid').find('tr:odd').addClass('trodd');
			$('#mine-publish-all-grid').find('tr:even').addClass('treven');
		}
		
	}
	
	/**
	 * 流程列表事件
	 */
	var bindAllFlowGridEvent = function(){
		var grid = $('#mine-publish-all-grid');
		grid.find(".publishBtn").unbind("click").bind("click",function(e){
			e.stopPropagation();
			var rowid = $(e.target).attr('rowid');
			var row = grid.jqGrid("getRowData", rowid);
			var dialog = $('<div>').append("<label style='margin-right:10px'>" + TempoUtils.locale("mine.publish-all-flow-label-publishName") + "：</label><input name='publishName' style='width:200px' />").dialog({
				width : 400,
				minHeight: 100,
				autoOpen:true,
				title: TempoUtils.locale("mine.publish-all-flow-label-publishName"),
				modal:true,
				close : function(){
					dialog.dialog("destroy");
				},
				open : function(){
					$(this).find('input[name="publishName"]').val(row.name);
				},
				buttons:[{
					text:TempoUtils.locale("mine.publish-all-flow-dialog-okbtn"),
					click:function(){
						var name = dialog.find('input[name="publishName"]').val().trim();
						if(name && name.length > 0){
							publishFlow(dialog, row, name);
						}else{
							$("<div/>").alert({msg : TempoUtils.locale("mine.publish-emptyname"), height : 280});
						}
					}
				},{
					text:TempoUtils.locale("mine.publish-all-flow-dialog-cancelbtn"),
					click:function(){
						dialog.dialog("destroy");
					}
				}]
			})
			
		});
	}
	
	/**
	 * 发布流程
	 */
	var publishFlow = function(dialog, data, name){
		var flowId = data.id;
		$.ajax({
			url:contextPath+"/api/ai/mine/publish/savePublish",
			data:{
				flowId: flowId,
				sceneId : analyseId,
				name : name
			},
			dataType:'json',
			type:'post',
			success:function(result){
				if(result && result.success){
					dialog.dialog("destroy");
					var data = result.data;
					$('#mine-published-grid').jqGrid('addRowData',data.id, data, 0);
					resetPublishedGridRowColor();
				}else{
					var errorCode = result.data;
					//保存失败
					if(errorCode == 0){
						$("<div/>").alert({msg : TempoUtils.locale("mine.publish-savefailed"), height : 280});
					}else{
						//名称重复
						$("<div/>").alert({msg : TempoUtils.locale("mine.publish-nameexists"), height : 280});
					}
				}
			}
		});
	}
	
	/**
	 * 初始化全部流程列表
	 */
	this.initPublishFlowGrid = function(data){
		if(!this.grid){
			this.grid = $('#mine-published-grid').jqGrid({
				datatype : "local",
				data : data,
				height : $('#mine-published-grid').parent().height() - 85,
				width : $('#mine-published-grid').parent().width()-5,
				rownumbers : true,
				shrinkToFit : true,
				hoverrows : false,
				resizable:false,
				loadui:'disable',
				colNames : [ 'id', 
				             TempoUtils.locale("mine.publish-published-flow-grid-column-name"),
				             TempoUtils.locale("mine.publish-published-flow-grid-column-author"),
				             TempoUtils.locale("mine.publish-published-flow-grid-column-createtime"),
				             TempoUtils.locale("mine.publish-published-flow-grid-column-relatedJobs"),
				             TempoUtils.locale("mine.publish-published-flow-grid-column-relatedServices"),
				             TempoUtils.locale("mine.publish-grid-column-opt")],
				colModel : [{
							name : 'id',
							index : 'id',
							hidden : true
						},{
							name : 'name',
							index : 'name',
							resizable:false,
							sortable : false,
							formatter : function(obj, grid, rows, state) {
								return obj;
							}
						},{
							name : 'author',
							index : 'author',
							width : 60,
							sortable:false
						},{
							name : 'publishTime',
							index : 'publishTime',
							resizable:false,
							sortable : false,
							width : 120,
							formatter : function(obj, grid, rows, state) {
								if(obj && $.isNumeric(obj)){
									return DateUtils.formatDateTime(new Date(obj), 'yyyy-MM-dd HH:mm:ss');
								}
								return obj;
							}
						},{
							name : 'relatedJobs',
							resizable : false,
							sortable : false,
							width : 100
						},{
							name : 'relatedServices',
							resizable : false,
							sortable : false,
							width : 100
						},{
							name : 'opt',
							index : '',
							sortable : false,
							width : 100,
							align : 'left',
							fixed : false,
							width : 60,
							formatter : function(obj, grid, rows, state) {
								var rename = $("<a>").attr("href", "javascript:;void(0)").append($("<span>").attr("rowid", rows.id).addClass("ui-icon ui-icon-pencil")).attr("title", TempoUtils.locale("mine.publish-published-flow-grid-optrename")).addClass('ui-corner-all gridoptbtn rename-publish-btn');
								var del = $("<a>").attr("href", "javascript:;void(0)").append($("<span>").attr("rowid", rows.id).addClass("ui-icon ui-icon-minus")).attr("title", TempoUtils.locale("mine.publish-published-flow-grid-optdel")).addClass('ui-corner-all gridoptbtn delete-publish-btn');
								var view = $("<a>").attr("href", "javascript:;void(0)").append($("<span>").attr("rowid", rows.id).addClass("ui-icon ui-icon-image")).attr("title", TempoUtils.locale("mine.publish-published-flow-grid-optview")).addClass('ui-corner-all gridoptbtn view-flow-btn');
								return rename.prop("outerHTML") + "&nbsp;" + del.prop("outerHTML") + "&nbsp;" + view.prop("outerHTML");
	
							}
						}],
				gridComplete : function(rowid,row) {
					bindPublishGridEvent();
				},
				loadComplete : function(datas){
					resetPublishedGridRowColor();
				},
				viewrecords : true
			});
		}else{
			this.grid.jqGrid('clearGridData');
			if(data && data.length > 0){
				for (var i = 0; i < data.length; i++) {
					this.grid.jqGrid('addRowData', data[i].id, data[i], i);
				}
			}
			resetPublishedGridRowColor();
		}
	}
	
	var resetPublishedGridRowColor = function(){
		$('#mine-published-grid').find('tr:odd').removeClass('treven')
		$('#mine-published-grid').find('tr:even').removeClass('trodd')
		$('#mine-published-grid').find('tr:odd').addClass('trodd');
		$('#mine-published-grid').find('tr:even').addClass('treven');
	}

	/**
	 * 发布列表列表事件
	 */
	var bindPublishGridEvent = function(){
		var grid = $('#mine-published-grid');
		grid.find(".delete-publish-btn").unbind("click").bind("click",function(e){
			e.stopPropagation();
			var rowid = $(e.target).attr('rowid');
			var row = grid.jqGrid("getRowData", rowid);
			deletePublishFlow(row);
		});
		grid.find(".view-flow-btn").unbind("click").bind("click",function(e){
			e.stopPropagation();
			var rowid = $(e.target).attr('rowid');
			var row = grid.jqGrid("getRowData", rowid);
			viewPublishFlow(row);
		});
		grid.find(".rename-publish-btn").unbind("click").bind("click",function(e){
			e.stopPropagation();
			var rowid = $(e.target).attr('rowid');
			var row = grid.jqGrid("getRowData", rowid);
			renamePublishFlow(row);
		});
	}
	
	/**
	 * 删除发布
	 */
	var deletePublishFlow = function(data){
		var flowId = data.id;
		$("<div/>").confirm({
			title :  TempoUtils.locale("mine.publish-btn-delete"), 
			msg :  TempoUtils.locale("mine.publish-published-flow-grid-delete-confirm"),
			height : 180,
			width : "auto",
			ok : function(){
				$.ajax({
					url:contextPath+"/api/ai/mine/publish/deletePublish",
					data:{
						id : flowId
					},
					dataType:'json',
					type:'post',
					success:function(result){
						if(result){
							$('#mine-published-grid').jqGrid('delRowData',flowId);
							resetPublishedGridRowColor();
						}
					}
				});
			}
		});
	}
	
	/**
	 * 查看流程图
	 */
	var viewPublishFlow = function(data){
		$.ajax({
			url:contextPath+"/api/ai/mine/publish/getFlowGraphData",
			data:{
				id : data.id
			},
			dataType:'json',
			type:'post',
			success:function(result){
				if(result){
					var viewDialog = $('<div>');
					var graph = $('<div>').appendTo(viewDialog);
					viewDialog.window({title: TempoUtils.locale("mine.publish-flowGraph"), autoMax: true, allowMax: true, height:600,width:1000});
					renderBoard(result, graph)
					graph.miningboard("updateSize");
				}
			}
		});
		
	}
	
	var renamePublishFlow = function(data){
		var dialog = $('<div>').append("<label style='margin-right:10px'>" + TempoUtils.locale("mine.publish-all-flow-label-publishName") + "：</label><input name='publishName' style='width:200px' />").dialog({
			width : 400,
			minHeight: 100,
			autoOpen:true,
			title: TempoUtils.locale("mine.publish-all-flow-label-publishName"),
			modal:true,
			close : function(){
				dialog.dialog("destroy");
			},
			open : function(){
				$(this).find('input[name="publishName"]').val(data.name);
			},
			buttons:[{
				text:TempoUtils.locale("mine.publish-all-flow-dialog-okbtn"),
				click:function(){
					var name = dialog.find('input[name="publishName"]').val().trim();
					if(name == data.name){
						dialog.dialog("destroy");
						return;
					}
					if(name &&  name.length > 0){
						$.ajax({
							url:contextPath+"/api/ai/mine/publish/renamePublish",
							data:{
								id : data.id,
								name : name,
								sceneId : analyseId
							},
							dataType:'json',
							type:'post',
							success:function(result){
								if(result && result.success){
									dialog.dialog("destroy");
									data.name = name;
									delete data.opt;
									$('#mine-published-grid').jqGrid('setRowData',data.id, data);
									resetPublishedGridRowColor();
								}else{
									var errorCode = result.data;
									//保存失败
									if(errorCode == 0){
										$("<div/>").alert({msg : TempoUtils.locale("mine.publish-savefailed"), height : 280});
									}else{
										//名称重复
										$("<div/>").alert({msg : TempoUtils.locale("mine.publish-nameexists"), height : 280});
									}
								}
							}
						});
					}else{
						$("<div/>").alert({msg : TempoUtils.locale("mine.publish-emptyname"), height : 280});
					}
				}
			},{
				text:TempoUtils.locale("mine.publish-all-flow-dialog-cancelbtn"),
				click:function(){
					dialog.dialog("destroy");
				}
			}]
		});
	}
}